home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gscpixel.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.3 KB  |  105 lines

  1. /* Copyright (C) 1997, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gscpixel.c,v 1.3 2000/09/19 19:00:26 lpd Exp $ */
  20. /* DevicePixel color space and operation definition */
  21. #include "gx.h"
  22. #include "gserrors.h"
  23. #include "gsrefct.h"
  24. #include "gxcspace.h"
  25. #include "gscpixel.h"
  26. #include "gxdevice.h"
  27.  
  28. /* Define the DevicePixel color space type. */
  29. private cs_proc_equal(gx_equal_DevicePixel);
  30. private cs_proc_restrict_color(gx_restrict_DevicePixel);
  31. private cs_proc_remap_concrete_color(gx_remap_concrete_DevicePixel);
  32. private cs_proc_concretize_color(gx_concretize_DevicePixel);
  33. private const gs_color_space_type gs_color_space_type_DevicePixel = {
  34.     gs_color_space_index_DevicePixel, true, false,
  35.     &st_base_color_space, gx_num_components_1,
  36.     gx_no_base_space, gx_equal_DevicePixel,
  37.     gx_init_paint_1, gx_restrict_DevicePixel,
  38.     gx_same_concrete_space,
  39.     gx_concretize_DevicePixel, gx_remap_concrete_DevicePixel,
  40.     gx_default_remap_color, gx_no_install_cspace,
  41.     gx_no_adjust_cspace_count, gx_no_adjust_color_count
  42. };
  43.  
  44. /* Test whether one DevicePixel color space equals another. */
  45. private bool
  46. gx_equal_DevicePixel(const gs_color_space *pcs1, const gs_color_space *pcs2)
  47. {
  48.     return pcs1->params.pixel.depth == pcs2->params.pixel.depth;
  49. }
  50.  
  51. /* Initialize a DevicePixel color space. */
  52. int
  53. gs_cspace_init_DevicePixel(gs_color_space * pcs, int depth)
  54. {
  55.     switch (depth) {
  56.     case 1:
  57.     case 2:
  58.     case 4:
  59.     case 8:
  60.     case 16:
  61.     case 24:
  62.     case 32:
  63.         break;
  64.     default:
  65.         return_error(gs_error_rangecheck);
  66.     }
  67.     gs_cspace_init(pcs, &gs_color_space_type_DevicePixel, NULL);
  68.     pcs->params.pixel.depth = depth;
  69.     return 0;
  70. }
  71.  
  72. /* ------ Internal routines ------ */
  73.  
  74. /* Force a DevicePixel color into legal range. */
  75. private void
  76. gx_restrict_DevicePixel(gs_client_color * pcc, const gs_color_space * pcs)
  77. {
  78.     /****** NOT ENOUGH BITS IN float OR frac ******/
  79.     floatp pixel = pcc->paint.values[0];
  80.     ulong max_value = (1L << pcs->params.pixel.depth) - 1;
  81.  
  82.     pcc->paint.values[0] = (pixel < 0 ? 0 : min(pixel, max_value));
  83. }
  84.  
  85.  
  86. /* Remap a DevicePixel color. */
  87.  
  88. private int
  89. gx_concretize_DevicePixel(const gs_client_color * pc, const gs_color_space * pcs,
  90.               frac * pconc, const gs_imager_state * pis)
  91. {
  92.     /****** NOT ENOUGH BITS IN float OR frac ******/
  93.     pconc[0] = (frac) (ulong) pc->paint.values[0];
  94.     return 0;
  95. }
  96.  
  97. private int
  98. gx_remap_concrete_DevicePixel(const frac * pconc,
  99.     gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
  100.                   gs_color_select_t select)
  101. {
  102.     color_set_pure(pdc, pconc[0] & ((1 << dev->color_info.depth) - 1));
  103.     return 0;
  104. }
  105.